package com.itheima;

import com.itheima.dao.AccountDao;
import com.itheima.service.AccountService;
import com.itheima.service.impl.AccountServiceImpl;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * Hello world!
 */
public class App {
    public static void main(String[] args) {


        //以前写法
        //AccountDao accountDao=new AccountDao();


        //换spring写法

        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");



        //我要个dao
        //Object accountDao21 = context.getBean("accountDao2");

        //System.out.println(accountDao21);

        //AccountDao accountDao22 = (AccountDao) context.getBean("accountDao2");

        //System.out.println(accountDao22);
        //创建对象 默认单例!!!!


        ///accountDao22.sayHello();

        //指明名字 和类型
        //AccountDao accountDao = context.getBean("accountDao2", AccountDao.class);

        //accountDao.sayHello();


        //获取对象
        //根据类型  获取对象  有前提  该种类 配置只能有一份
        AccountDao accountDao = context.getBean(AccountDao.class);


        accountDao.sayHello();




        //现在 获取service对象
        //原始方式
        //AccountServiceImpl accountService = context.getBean(AccountServiceImpl.class);


        //利用多态特性
        //AccountService accountService = context.getBean(AccountServiceImpl.class);

        //context.getBean(希望的类型啊 !!!!!)
        AccountService accountService = context.getBean(AccountService.class);
        System.out.println("正经人啊");


        //鼓励大家

        //接口  变量名=context.getBean(接口.class);




    }
}
